<template>
    <!-- 标题区域 -->
    <van-nav-bar title="商品分类" left-text="返回" left-arrow @click-left="() => { $router.push('/') }" fixed />
    <div style="height: 45px;"></div>
    <!-- 分类渲染 laout布局 -->
    <van-row>
        <!-- 左侧 -->
        <van-col span="6">
            <!-- 侧边栏 -->
            <van-sidebar v-model="active">
                <van-sidebar-item v-for="item in claData" :title="item.cat_name" />
            </van-sidebar>
        </van-col>
        <!-- 右侧  根据左侧选中的-->
        <van-col span="18">
            <div v-for="item in claData[active]?.children">
                <h4>{{ item.cat_name }}</h4>
                <!-- 宫格渲染 -->
                <router-link :to="'/goods/' + item.cat_name">
                    <van-grid :column-num="4">
                        <van-grid-item v-for="items in item.children" :icon="items.cat_icon" :text="items.cat_name" />
                    </van-grid>
                </router-link>

            </div>
        </van-col>
    </van-row>

</template>

<script setup>
import { ref } from 'vue'
import { claApi } from '@/api/api'
// 自定义分类数据
let claData = ref([])
// 分类请求
claApi().then(res => {
    console.log('分类数据', res);
    claData.value = res.data.message
})
// 默认的左侧选中
const active = ref(0);
</script>

<style lang="scss" scoped></style>